<?php
if (!isset($_SESSION['consultorio'])){
session_start();
}
//echo "pase";
require_once 'jq-configin.php';
//require_once ('/Applications/MAMP/htdocs/HS/jqSuitePHP_4_1_2_2/jq-config.php');
// include the jqGrid Class

require_once ABSPATH."php/jqGrid.php";
// include the driver class
require_once ABSPATH."php/jqGridPdo.php";
// Connection to the server
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8");


// Create the jqGrid instance
$grid = new jqGridRender($conn);
// Write the SQL Query

// Write the SQL Query

$grid->SelectCommand = "SELECT camas.idCama,sectorconsultorio.descSectorConsultorio,camas.NumeroCama,paciente.NumDoc,
paciente.Apellido FROM camas INNER JOIN sectorconsultorio 
ON camas.Estado='Ocupada' AND sectorconsultorio.idConsultorio='".$_SESSION['consultorio']."' AND sectorconsultorio.idSectorConsultorio=camas.idSectorConsultorio
INNER JOIN paciente  ON camas.idPaciente=paciente.idpaciente";

$grid->table = 'camas'; 
//echo $grid->SelectCommand ;
// Set the table to where you update the data
//$grid->table = 'paciente';
// Set output format to json
$grid->dataType = 'json';
// Let the grid create the model

$grid->setColModel();

$grid->setUrl("Internacion/Grid/gridinternados.php");

// Set the url from where we obtain the data
// Set the url from where we obtain the data
// Set some grid options
$grid->setGridOptions(array(
        "caption"=>"Pacientes Internados", 
        "width"=>500,
        "height"=>60,  
    "rowNum"=>20,
    "rowList"=>array(20,40,60),
    "hiddengrid"=>false,    
        "hidegrid"=>true,
    "shrinkToFit"=>false,
    "sortname"=>"idCama"
));

// Set the table to where you add the data 

$grid->setColProperty('idCama', array("label"=>"ID", "width"=>50));
$grid->setColProperty('descSectorConsultorio', array("label"=>"Sector", "width"=>150));
$grid->setColProperty('NumeroCama', array("label"=>"Cama", "width"=>50));
$grid->setColProperty('Apellido', array("label"=>"Apellido", "width"=>150));
$grid->setColProperty('NumDoc', array("label"=>"Documento", "width"=>100));

$custom3 = <<<HC3
jQuery("#getPacienteInternado").click(function(){
    var selrp = jQuery('#gridPacientesinternados').jqGrid('getGridParam','selrow');

    if(selrp)     
    {  
            //  $( "#idNumCama" ).show('200'); 
           //document.getElementById("idNumCama").innerHTML=selr1; 
           
              var selrrow = jQuery('#gridPacientesinternados').jqGrid('getRowData',selrp);

       document.nameFormEgresoInternacion.nameSectorEgresoInternacion.value = selrrow.descSectorConsultorio;
       document.nameFormEgresoInternacion.nameSectorEgresoInternacion.name = selrrow.descSectorConsultorio;
       
       document.nameFormEgresoInternacion.nameNombreEgresoInternacion.value = selrrow.Apellido;
       document.nameFormEgresoInternacion.nameNombreEgresoInternacion.name = selrrow.Apelido;
       
       document.nameFormEgresoInternacion.nameDocumentoEgresoInternacion.value = selrrow.NumDoc;
       document.nameFormEgresoInternacion.nameDocumentoEgresoInternacion.name = selrrow.NumDoc;
    }
    
	if(!selr1) alert("No selected row");
   return false;
    
});
HC3;
$grid->setJSCode($custom3); 


$grid->toolbarfilter = true; 
// Enable navigator

$grid->navigator = true;
// Enable only editing
//$grid->setNavOptions('navigator', array("excel"=>false,"add"=>false,"edit"=>false,"del"=>false,"view"=>false));

$grid->setNavOptions('navigator', array("excel"=>false,"add"=>false,"edit"=>false,"del"=>false,"view"=>false, "search"=>true));

// Enjoy
$grid->renderGrid('#gridPacientesinternados','#pagerPacientesinternados',true, null, null, true,true);
// we set the select for ship city 

//$grid->setSelect("ShipCity", "SELECT DISTINCT ShipCity, ShipCity AS CityName FROM orders ORDER BY 2", false, false, true, array(""=>"All"))

$conn = null;

?> 
 


